<template>
<h1>猜数字练习</h1>
  <input type="text" v-model="num" placeholder="请输入1-100的数字">
  <button @click="guess">猜一猜</button>
  <p>您猜的结果是:{{ result}}</p>
</template>

<script setup>
import {ref} from "vue";
let x = parseInt(Math.random()*100)+1;
console.log("打个小抄:"+x)
const num = ref('');
const result = ref('');
const guess=()=>{
  num.value = parseInt(num.value);
  if(num.value.trim==''||isNaN(num.value)){
    num.value = '';
    alert("请输入数字");
    return;
  }
  if(num.value>x){
    num.value = '';
    result.value=("猜大了");
  }else if(num.value<x){
    num.value = '';
    result.value=("猜小了");
  }else{
    num.value = '';
    result.value=("恭喜你猜对了");
  }
}


</script>


<style scoped>

</style>